package chapter26;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/28 15:06
 */
public class StreamTeat {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(new Student[]{
                new Student("zhangsan", 87.2),
                new Student("li", 87.2),
                new Student("wangwu", 97.4)});

        List<Student> above90List = students.stream()
                .filter(s -> s.getScore() >= 90)
                .collect(Collectors.toList());
        System.out.println(above90List);

        List<String> nameList = students.stream()
                .map(Student::getName)
                .collect(Collectors.toList());

        System.out.println(nameList);

        List<String> above90Name = students.stream()
                .filter(s -> s.getScore() > 90)
                .map(Student::getName)
                .collect(Collectors.toList());
        System.out.println(above90Name);

        double sum = students.stream().mapToDouble(Student::getScore).sum();
        System.out.println(sum);

        Student student = students.stream().max(Comparator.comparingDouble(Student::getScore).reversed()).get();
        System.out.println(student);
    }
}
